#ifndef UCLCODE_H
#define UCLCODE_H

//#include "applicationobj_c.h"

//#include "c:\verixaps\ucl\include\applicationobj.h"
//#include "c:\verixVaps\ucl\ver161\include\applicationobj.h"
#include <applicationobj.h>

#include "comm.h"

typedef struct tagAppObj
{
	ApplicationObj super;
	short (*SetParam)(short paramId, unsigned char *buffer, short size);
}AppObj; 

AppObj *CreateAppObj(short type);

short GetParamLandLine(short paramId, unsigned char *buffer, short size);
short SetParamLandLine(short paramId, unsigned char *buffer, short size);
short GetParamGsm(short paramId, unsigned char *buffer, short size);
short SetParamGsm(short paramId, unsigned char *buffer, short size);
short NotifyLandLine(short state);
short NotifyGsm(short state);

short GetParamCO(short paramId, unsigned char *buffer, short size);
short SetParamCO(short paramId, unsigned char *buffer, short size);
short NotifyCO(short state);

short GetParamWiFi(short paramId, unsigned char *buffer, short size);
short SetParamWiFi(short paramId, unsigned char *buffer, short size);
short NotifyWiFi(short state);

short GetParamGprs(short paramId, unsigned char *buffer, short size);
short SetParamGprs(short paramId, unsigned char *buffer, short size);
short NotifyGprs(short state);

short GetParamCdma(short paramId, unsigned char *buffer, short size);
short SetParamCdma(short paramId, unsigned char *buffer, short size);
short NotifyCdma(short state);

void ShowUclResult(short);

int inInitUclCommunication (COMM_OBJECT *obCommunication);
int inBeginUclCommunication (COMM_OBJECT *obCommunication, int inCPTIndex, VS_BOOL fUsePrimaryLine);
int inCheckUclCommunication (COMM_OBJECT *obCommunication);
int inSendUclCommunication (COMM_OBJECT *obCommunication, char *pchSendBuff, int inSendSize, VS_BOOL fConfirmSend, int inTimeout, long lnMessage);
int inReceiveUclCommunication (COMM_OBJECT *obCommunication, char *pchReceiveBuff, int inReceiveSize, int inReceiveTimeout, long lnMessage);
int inFlushUclCommunication (void);
int inEndUclCommunication (COMM_OBJECT *obCommunication);
int inDeInitUclCommunication (COMM_OBJECT *obCommunication);

int inProperlyUclCreate(void);
int inUpdateWirelessStatus(void);
int inHostConnectionTest(void);

unsigned long ulGetConnectionTime(void);
unsigned long ulGetKeepAliveTime(void);
unsigned long ulGetFirstSocketConnectTimeoutTime(void);

int inGetCommLink(void);
int inGetCurrentUCLCommLink(void);


int inBackGroundWirelessControl(int inMode, int inDesiredStatus);

int inProperlyOpenModem(void);
int inProperlyCloseModem(void);
int inForceCloseModem(void);
int inProperlyCheckRegisterStatus(void);
int inProperlyPPPConnecting(void);
int inProperlyCheckPPPConnecting(void);
int inForcePPPDisconnect(void);
int inProperlySocketConnect(void);
int inProperlySocketDisconnect(void);
int inForceSocketDisconnect(void);
int inPvsSetModemToSleep(void);

void vdPvsDisplayWirelessModemStatus(int inForcedStatus);
int inPing(char *Addr);


int inLoadMinAndAKey(void);
int inGetPPPAuthType(void);

int fSSL(void);
int fAES(void);
#ifndef __arm
int inAES_Encrypt (char *szData, int inDataLen);
int inAES_Decrypt (char *szEncData, int inEncDataLen);
int inPvsAesEncrypt (unsigned char *ucInput, int inInputLen, unsigned char *ucOutput, int *inOutputLen);
int inPvsAesDecrypt (unsigned char *ucInput, int inInputLen, unsigned char *ucOutput, int *inOutputLen);
#endif
#ifdef __arm
int inPvsAesEncrypt (unsigned char *ucInput, int inInputLen, unsigned char *ucOutput, int *inOutputLen);
int inPvsAesDecrypt (unsigned char *ucInput, int inInputLen, unsigned char *ucOutput, int *inOutputLen);
#endif


#define TLE_MAX_DATA_SZ		500
#define MODE_ECB			1			// Electronic Code Book
#define MODE_CBC			2			// Cipher Block Chaining

#define PAD_NULL			1		// Pad with Nulls
#define PAD_NULL_NUM_BYTES	2		// Pad with Nulls and end with Number of Bytes
#define AES_BLOCK_SIZE	16			// Bytes
#define AES_KEY_LENGTH	16			// Bytes

///// AES ////////////////////
typedef struct libencrypt
{
	int iEncryptAlgo;
	int	iMode;	
	int iPadChar;
	int iBlockSize;
	int iKeyLen;

	// This function allows the specific encryption implementation to initialize 
	//	the contents of this cryptolib structure
	// iMode = 0 means use the default value.
	int (*Init)	   (int, int, struct libencrypt *);

	// Function pointer to the specific encryption function
	int (*iEncrypt)(	unsigned char *, int ,
						unsigned char *, int *,
						unsigned char *, int ,
						struct libencrypt *);

	// Function pointer to the specific decryption function
	int (*iDecrypt)(	unsigned char *, int,
						unsigned char *, int *,
						unsigned char *, int, 
						struct libencrypt *);
} LIBENCRYPT;

#define MODEM_NOT_OPEN			1000
#define MODEM_OPENED			2000
#define MODEM_REGISTERING		2500
#define MODEM_REGISTERED		3000
#define MODEM_PPP_CONNECTING	3500
#define MODEM_PPP_CONNECTED		4000
#define MODEM_SOCKET_CONNECTED	5000

#define UCL_COMM	"UCL.COMM"
#define UCL_HOSTIP	"UCL.HOSTIP"
#define UCL_LOCALIP	"UCL.LOCALIP"
#define UCL_SPACC	"UCL.SPACC"
#define UCL_PARAM	"UCL.PARAM"

#define UCL_PPPAUTH	"UCL.PPPAUTH"
#define UCL_ENCRYPT	"UCL.ENCRYPT"

#endif